#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h> 
#include <stdlib.h>
#include <assert.h>
#include "app_platform/cntl_info.h"
#include "accountdao.h"


#include "c2cplatform/component/dal/dal_set.h"
#include "c2cent/storage/mysqlstorage.h"
#include "c2cplatform/component/dal/db_operator_mysql_set.h"

using namespace c2cplatform::component::dal;
using namespace c2cent::storage;

using namespace erp::account::dao;

CPP_SELF_DEFINE_START
/**
*  请在这里增加自定义的成员变量和函数及其他内容，否则无法合并代码
**/
#include "erp/comm/erp_macro_define.h"
#include "erp/comm/erp_errno_define.h"
using namespace c2cent::library::wwlog;
using namespace c2cent::library::wtimeelf;
using namespace erp::comm;
CPP_SELF_DEFINE_END


erp::account::db::CAccountDBOperator CAccountDao::m_oDBOperator;

/**
 *构建函数
 */
CAccountDao::CAccountDao(enum DeployMethod method)
{

}

/**
 *析构函数
 */
CAccountDao::~CAccountDao()
{

}


/**
 *每一次服务请求时，container都会调用此方法来清空数据
 */
void  CAccountDao::Reset()
{

}


int  CAccountDao::Initialize(IUserDefineCntl* pCntl)
{
	int iRet = 0;

    uint32_t dwLogSwitch=WLOG_OPEN|WLOG_KEY_OPEN|WLOG_ERR_OPEN;

    uint32_t dwCanLogRemote = 0;
    std::string strLogModule="dao_account";
    std::cout<<"File:"<<__FILE__<<" Complie Date: "<<__DATE__<<" "<<__TIME__<<std::endl;

    GetUintConfig(LogSwitch);
    GetStringConfig(LogModule);
    GetUintConfig(CanLogRemote);

    // 初始化日志
    if( C2C_WWLOG->QuickInitForAPP2(strLogModule.c_str(),B2B2CWW_LOG_APP_FILE_PATH, dwCanLogRemote, dwLogSwitch)!= 0)
    {
        std::cerr << "C2C_WWLOG->QuickInitForAPP2 Failed" << std::endl;
        return -1;
    }
    C2C_WW_LOG("C2C_WWLOG->QuickInitForAPP2 OK!");

	iRet = m_oDBOperator.InitDB(pCntl);
    if( iRet != 0)
    {
        C2C_WW_LOG_ERR(iRet, "Init DB failed. iRetCode:%d", iRet);
        return iRet;
    }
    C2C_WW_LOG("InitDB() Success!");

	return iRet;
}


/**
 *
 * 添加/修改来往单位；传入来往单位SysNo不为0时则进行修改，反之则进行添加；
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param BusinessUnitsDdo businessUnitsDdo: 分支机构Ddo，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param uint64_t SysNo: 返回相应的SysNo  	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::ModifyBusinessUnits(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				const erp::account::ddo::CBusinessUnitsDdo& oBusinessUnitsDdo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				uint64_t& ddwSysNo,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码
    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	dwRet = this->CheckBusinessUnitsDdo(oBusinessUnitsDdo, strErrmsg);

	if (dwRet != 0)
	{
	    C2C_WW_LOG_ERR(dwRet,"%s ParamErr:%s! MachineKey:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		__FUNCTION__, strErrmsg.c_str(), strMachineKey.c_str(), rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

		return dwRet;
	}

	dwRet = this->GetRealSysNo(rCntlInfo, strMachineKey, strSource, dwSceneId, ERP_YUN_TYPE_BUSINESSUNITS, ddwSysNo);

	if (dwRet != 0)
	{
		return dwRet;
	}

    dwRet = m_oDBOperator.ModifyBusinessUnits(rCntlInfo,
			strMachineKey,
			strSource,
			dwSceneId,
			dwOption,
			oBusinessUnitsDdo,
			strInReserve,
			strErrmsg,
			ddwSysNo,
			strOutReserve);

	if(dwRet!=0)
	{
	    C2C_WW_LOG_ERR(dwRet,"ModifyBusinessUnits Failed! OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s",
	    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,strErrmsg.c_str());
	    C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return dwRet;
	}
	
	return dwRet;
}

/**
 *
 * 删除来往单位（逻辑）
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param uint64_t businessUnitsSysNo: 需删除的来往单位的SysNo，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::DeleteBusinessUnits(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				uint64_t ddwBusinessUnitsSysNo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码

    C2C_WW_LOG("DeleteBusinessUnits %s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

    dwRet = m_oDBOperator.DeleteBusinessUnits(rCntlInfo,
			strMachineKey,
			strSource,
			dwSceneId,
			dwOption,
			ddwBusinessUnitsSysNo,
			strInReserve,
			strErrmsg,
			strOutReserve);
	
	if(dwRet!=0)
	{
	    C2C_WW_LOG_ERR(dwRet,"DeleteBusinessUnits Failed! OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s",
	    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,strErrmsg.c_str());
	    C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return dwRet;
	}

	return dwRet;
}

/**
 *
 * 根据分支机构ID批量获取分支机构信息
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param Set businessUnitsSysNo: 需获取的来往单位的SysNo，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param Map errorCode: 获取失败的错误码 	[out]
 *@param Map errorMsg: 获取失败的错误信息 	[out]
 *@param Map businessUnitsDdo: 获取成功的来往单位信息 	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::GetBusinessUnitsBySysNos(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				const std::set<uint64_t >& setBusinessUnitsSysNo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::map<uint64_t,uint32_t >& mapErrorCode,
				std::map<uint64_t,std::string >& mapErrorMsg,
				std::map<uint64_t,erp::account::ddo::CBusinessUnitsDdo >& mapBusinessUnitsDdo,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码
    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	dwRet = this->CheckBusinessUnitsSysNos(setBusinessUnitsSysNo, strErrmsg);

	if (dwRet != 0)
	{
	    C2C_WW_LOG_ERR(dwRet,"%s ParamErr:%s! MachineKey:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		__FUNCTION__, strErrmsg.c_str(), strMachineKey.c_str(), rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

		return dwRet;
	}

    dwRet = m_oDBOperator.GetBusinessUnitsBySysNos(rCntlInfo,
			strMachineKey,
			strSource,
			dwSceneId,
			dwOption,
			setBusinessUnitsSysNo,
			strInReserve,
			strErrmsg,
			mapErrorCode,
			mapErrorMsg,
			mapBusinessUnitsDdo,
			strOutReserve);
	
	if(dwRet!=0)
	{
	    C2C_WW_LOG_ERR(dwRet,"GetBusinessUnitsByIds Failed! OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s",
	    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,strErrmsg.c_str());
	    C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return dwRet;
	}

	return dwRet;
}

/**
 *
 * 根据过滤条件查询来往单位列表信息
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param BusinessUnitsFilterDdo filter: 过滤器，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param uint32_t total: 分支机构总数 	[out]
 *@param Vector businessUnitsDdo: 分支机构列表信息 	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::GetBusinessUnitsByFilter(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				const erp::account::ddo::CBusinessUnitsFilterDdo& oFilter,
				const std::string& strInReserve,
				std::string& strErrmsg,
				uint32_t& dwTotal,
				std::vector<erp::account::ddo::CBusinessUnitsDdo >& vecBusinessUnitsDdo,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码

    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	dwRet = this->CheckBusinessUnitsFilterDdo(oFilter, strErrmsg);

	if (dwRet != 0)
	{
	    C2C_WW_LOG_ERR(dwRet,"%s ParamErr:%s! MachineKey:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		__FUNCTION__, strErrmsg.c_str(), strMachineKey.c_str(), rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

		return dwRet;
	}

    dwRet = m_oDBOperator.GetBusinessUnitsByFilter(rCntlInfo,
			strMachineKey,
			strSource,
			dwSceneId,
			dwOption,
			oFilter,
			strInReserve,
			strErrmsg,
			dwTotal,
			vecBusinessUnitsDdo,
			strOutReserve);
	
	if(dwRet!=0)
	{
	    C2C_WW_LOG_ERR(dwRet,"GetBusinessUnitsByFilter Failed! OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s",
	    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,strErrmsg.c_str());
	    C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return dwRet;
	}

	return dwRet;
}


/**
 *
 * 添加/修改职员；传入来往单位SysNo不为0时则进行修改，反之则进行添加；
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param EmployeeDdo employeeDdo: 职员Ddo，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param uint64_t SysNo: 返回相应的SysNo  	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::ModifyEmployee(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				const erp::account::ddo::CEmployeeDdo& oEmployeeDdo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				uint64_t& ddwSysNo,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码

    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	dwRet = this->CheckEmployeeDdo(oEmployeeDdo, strErrmsg);

	if (dwRet != 0)
	{
	    C2C_WW_LOG_ERR(dwRet,"%s ParamErr:%s! MachineKey:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		__FUNCTION__, strErrmsg.c_str(), strMachineKey.c_str(), rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

		return dwRet;
	}
	
	return dwRet;
}

/**
 *
 * 删除职员（逻辑）
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param uint64_t employeeSysNo: 需删除的职员的SysNo，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::DeleteEmployee(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				uint64_t ddwEmployeeSysNo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码
	
    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	return dwRet;
}

/**
 *
 * 根据职员ID批量获取职员信息
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param Set employeeSysNo: 需获取的职员的SysNo，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param Map errorCode: 获取失败的错误码 	[out]
 *@param Map errorMsg: 获取失败的错误信息 	[out]
 *@param Map employeeDdo: 获取成功的来往单位信息 	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::GetEmployeeBySysNos(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				const std::set<uint64_t >& setEmployeeSysNo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::map<uint64_t,uint32_t >& mapErrorCode,
				std::map<uint64_t,std::string >& mapErrorMsg,
				std::map<uint64_t,erp::account::ddo::CEmployeeDdo >& mapEmployeeDdo,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码
	
    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	dwRet = this->CheckEmployeeBySysNos(setEmployeeSysNo, strErrmsg);

	if (dwRet != 0)
	{
	    C2C_WW_LOG_ERR(dwRet,"%s ParamErr:%s! MachineKey:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		__FUNCTION__, strErrmsg.c_str(), strMachineKey.c_str(), rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

		return dwRet;
	}

	return dwRet;
}

/**
 *
 * 根据过滤条件查询职员列表信息
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param EmployeeFilterDdo filter: 过滤器，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param uint32_t total: 职员总数 	[out]
 *@param Vector businessUnitsDdo: 职员列表信息 	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::GetEmployeeByFilter(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				const erp::account::ddo::CEmployeeFilterDdo& oFilter,
				const std::string& strInReserve,
				std::string& strErrmsg,
				uint32_t& dwTotal,
				std::vector<erp::account::ddo::CEmployeeDdo >& vecBusinessUnitsDdo,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码

    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	dwRet = this->CheckEmployeeFilterDdo(oFilter, strErrmsg);

	if (dwRet != 0)
	{
	    C2C_WW_LOG_ERR(dwRet,"%s ParamErr:%s! MachineKey:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		__FUNCTION__, strErrmsg.c_str(), strMachineKey.c_str(), rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

		return dwRet;
	}
	
	return dwRet;
}

/**
 *
 * 根据主键查询信用额度
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param uint64_t branchSysNo: 分支机构SysNo，必填   [in]
 *@param uint64_t businessUnitsSysNo: 往来单位SysNo，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param CustomerCreditDdo customerCreditDdo: 信用额度信息 	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::GetCustomerCredit(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				uint64_t ddwBranchSysNo,
				uint64_t ddwBusinessUnitsSysNo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				erp::account::ddo::CCustomerCreditDdo& oCustomerCreditDdo,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码

    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);
	
	return dwRet;
}

/**
 *
 * 添加/修改信用额度；传入组合主键往来单位SysNo和分支机构SysNo
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param CustomerCreditDdo customerCreditDdo: 职员Ddo，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::ModifyCustomerCredit(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				const erp::account::ddo::CCustomerCreditDdo& oCustomerCreditDdo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码

    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	dwRet = this->CheckCustomerCreditDdo(oCustomerCreditDdo, strErrmsg);

	if (dwRet != 0)
	{
	    C2C_WW_LOG_ERR(dwRet,"%s ParamErr:%s! MachineKey:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		__FUNCTION__, strErrmsg.c_str(), strMachineKey.c_str(), rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

		return dwRet;
	}
	
	return dwRet;
}

/**
 *
 * 添加/修改联系人；传入联系人SysNo不为0时则进行修改，反之则进行添加；
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param ContactDdo contactDdo: 分支机构Ddo，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param uint64_t SysNo: 返回相应的SysNo  	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::ModifyContact(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				const erp::account::ddo::CContactDdo& oContactDdo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				uint64_t& ddwSysNo,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码

    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	dwRet = this->CheckContactDdo(oContactDdo, strErrmsg);

	if (dwRet != 0)
	{
	    C2C_WW_LOG_ERR(dwRet,"%s ParamErr:%s! MachineKey:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		__FUNCTION__, strErrmsg.c_str(), strMachineKey.c_str(), rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

		return dwRet;
	}
	
	return dwRet;
}

/**
 *
 * 删除联系人（逻辑）
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param uint64_t contactSysNo: 需删除的联系人的SysNo，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::DeleteContact(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				uint64_t ddwContactSysNo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码

    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	
	return dwRet;
}

/**
 *
 * 根据联系人SysNo批量获取联系人信息
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param Set contactSysNo: 需获取的联系人的SysNo，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param Map errorCode: 获取失败的错误码 	[out]
 *@param Map errorMsg: 获取失败的错误信息 	[out]
 *@param Map contactDdo: 获取成功的来往单位信息 	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::GetContactBySysNos(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				const std::set<uint64_t >& setContactSysNo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::map<uint64_t,uint32_t >& mapErrorCode,
				std::map<uint64_t,std::string >& mapErrorMsg,
				std::map<uint64_t,erp::account::ddo::CContactDdo >& mapContactDdo,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码

    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	dwRet = this->CheckContactSysNos(setContactSysNo, strErrmsg);

	if (dwRet != 0)
	{
	    C2C_WW_LOG_ERR(dwRet,"%s ParamErr:%s! MachineKey:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		__FUNCTION__, strErrmsg.c_str(), strMachineKey.c_str(), rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

		return dwRet;
	}
	
	return dwRet;
}

/**
 *
 * 根据过滤条件查询联系人信息
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t option: 功能选项，扩展选填   [in]
 *@param ContactFilterDdo filter: 过滤器，必填   [in]
 *@param String inReserve: 请求保留字   [in]
 *@param String errmsg: 错误信息  	[out]
 *@param uint32_t total: 分支机构总数 	[out]
 *@param Vector contactDdo: 分支机构列表信息 	[out]
 *@param String outReserve: 返回保留字   	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CAccountDao::GetContactByFilter(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwOption,
				const erp::account::ddo::CContactFilterDdo& oFilter,
				const std::string& strInReserve,
				std::string& strErrmsg,
				uint32_t& dwTotal,
				std::vector<erp::account::ddo::CContactDdo >& vecContactDdo,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = CheckCommParam(rCntlInfo, strMachineKey, strSource, dwSceneId);

	if (dwRet != 0)
	{
		return dwRet;
	}

	//TODO:业务代码

    C2C_WW_LOG("%s OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
    		rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

	dwRet = this->CheckContactFilterDdo(oFilter, strErrmsg);

	if (dwRet != 0)
	{
	    C2C_WW_LOG_ERR(dwRet,"%s ParamErr:%s! MachineKey:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		__FUNCTION__, strErrmsg.c_str(), strMachineKey.c_str(), rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);

		return dwRet;
	}
	
	return dwRet;
}


/**
 *
 * 判断来往单位ddo是否合法
 *
 *@param CBusinessUnitsDdo& oBusinessUnitsDdo: 过滤器，必填   [in]
 *@param String errmsg: 错误信息  	[out]
 *
 *@return  uint32_t : 0(合法) 其它非法
 *
 */
uint32_t CAccountDao::CheckBusinessUnitsDdo(
		const erp::account::ddo::CBusinessUnitsDdo& oBusinessUnitsDdo,
		std::string& strErrmsg)
{
	//参数校验
	//模版ID或者合作伙伴ID没设置，都是无法更新的
	if(oBusinessUnitsDdo.GetFullName().length()==0)
	{
		return ERR_ERP_YUN_STRING_EMPTYORNULL;
	}

	if(oBusinessUnitsDdo.GetName().length()==0)
	{
		return ERR_ERP_YUN_STRING_EMPTYORNULL;
	}

	return 0;
}


/**
 *
 * 判断来往单位的set SysNos是否合法
 *
 *@param set<uint64_t> setBusinessUnitsSysNo: 过滤器，必填   [in]
 *@param String errmsg: 错误信息  	[out]
 *
 *@return  uint32_t : 0(合法) 其它非法
 *
 */
uint32_t CAccountDao::CheckBusinessUnitsSysNos(
		const std::set<uint64_t> & setBusinessUnitsSysNo,
		std::string& strErrmsg)
{
	uint32_t dwRet = 0;
	//TODO:业务代码

	return dwRet;
}

/**
 *
 * 判断来往单位的Filter Ddo是否合法
 *
 *@param CBusinessUnitsFilterDdo oFilter: 过滤器，必填   [in]
 *@param String errmsg: 错误信息  	[out]
 *
 *@return  uint32_t : 0(合法) 其它非法
 *
 */
uint32_t CAccountDao::CheckBusinessUnitsFilterDdo(
		const erp::account::ddo::CBusinessUnitsFilterDdo& oFilter,
		std::string& strErrmsg)
{
	uint32_t dwRet = 0;
	//TODO:业务代码

	return dwRet;
}

/**
 *
 * 判断CEmployeeDdo是否合法
 *
 *@param CEmployeeDdo oEmployeeDdo: 过滤器，必填   [in]
 *@param String errmsg: 错误信息  	[out]
 *
 *@return  uint32_t : 0(合法) 其它非法
 *
 */
uint32_t CAccountDao::CheckEmployeeDdo(
		const erp::account::ddo::CEmployeeDdo& oEmployeeDdo,
		std::string& strErrmsg)
{
	uint32_t dwRet = 0;
	//TODO:业务代码

	return dwRet;
}

/**
 *
 * 判断set CEmployee SysNos是否合法
 *
 *@param set<uint64_t> setEmployeeSysNo: 过滤器，必填   [in]
 *@param String errmsg: 错误信息  	[out]
 *
 *@return  uint32_t : 0(合法) 其它非法
 *
 */
uint32_t CAccountDao::CheckEmployeeBySysNos(
		const std::set<uint64_t> & setEmployeeSysNo,
		std::string& strErrmsg)
{
	uint32_t dwRet = 0;
	//TODO:业务代码

	return dwRet;
}

/**
 *
 * 判断EmployeeFilterDdo是否合法
 *
 *@param CEmployeeFilterDdo oFilter: 过滤器，必填   [in]
 *@param String errmsg: 错误信息  	[out]
 *
 *@return  uint32_t : 0(合法) 其它非法
 *
 */
uint32_t CAccountDao::CheckEmployeeFilterDdo(
		const erp::account::ddo::CEmployeeFilterDdo& oFilter,
		std::string& strErrmsg)
{
	uint32_t dwRet = 0;
	//TODO:业务代码

	return dwRet;
}

/**
 *
 * 判断CCustomerCreditDdo是否合法
 *
 *@param CCustomerCreditDdo oCustomerCreditDdo: 过滤器，必填   [in]
 *@param String errmsg: 错误信息  	[out]
 *
 *@return  uint32_t : 0(合法) 其它非法
 *
 */
uint32_t CAccountDao::CheckCustomerCreditDdo(
		const erp::account::ddo::CCustomerCreditDdo& oCustomerCreditDdo,
		std::string& strErrmsg)
{
	uint32_t dwRet = 0;
	//TODO:业务代码

	return dwRet;
}

/**
 *
 * 判断CContactDdo是否合法
 *
 *@param CContactDdo oContactDdo: 过滤器，必填   [in]
 *@param String errmsg: 错误信息  	[out]
 *
 *@return  uint32_t : 0(合法) 其它非法
 *
 */
uint32_t CAccountDao::CheckContactDdo(
		 const erp::account::ddo::CContactDdo& oContactDdo,
		std::string& strErrmsg)
{
	uint32_t dwRet = 0;
	//TODO:业务代码

	return dwRet;
}

/**
 *
 * 判断setContactSysNo是否合法
 *
 *@param set<uint64_t> setContactSysNo: 过滤器，必填   [in]
 *@param String errmsg: 错误信息  	[out]
 *
 *@return  uint32_t : 0(合法) 其它非法
 *
 */
uint32_t CAccountDao::CheckContactSysNos(
		const std::set<uint64_t> & setContactSysNo,
		std::string& strErrmsg)
{
	uint32_t dwRet = 0;
	//TODO:业务代码

	return dwRet;
}

/**
 *
 * 判断CEmployeeDdo是否合法
 *
 *@param CEmployeeDdo oEmployeeDdo: 过滤器，必填   [in]
 *@param String errmsg: 错误信息  	[out]
 *
 *@return  uint32_t : 0(合法) 其它非法
 *
 */
uint32_t CAccountDao::CheckContactFilterDdo(
		const erp::account::ddo::CContactFilterDdo& oFilter,
		std::string& strErrmsg)
{
	uint32_t dwRet = 0;
	//TODO:业务代码

	return dwRet;
}

/**
 *
 * 如果传入的ddwSysNo为0，重新申请idmaker。
 *
 *@param String machineKey: 机器码，必填   [in]
 *@param String source: 调用来源，必填   [in]
 *@param uint32_t sceneId: 场景ID，必填   [in]
 *@param uint32_t BizType,: 申请的业务号   [in]
 *@param uint64_t ddwSysNo: 错误信息  	[in/out]
 *
 *@return  uint32_t : 0(合法) 其它非法
 *
 */
uint32_t CAccountDao::GetRealSysNo(
		const CCntlInfo& rCntlInfo,
		const std::string& strMachineKey,
		const std::string& strSource,
		const uint32_t dwSceneId,
		const ERP_YUN_IDMAKER_TYPE eBizType,
		uint64_t& ddwSysNo
	)
{
	if (ddwSysNo != 0)
	{
		return 0;
	}

	//我们打算要申请的数量
	const uint32_t ReqSize = 1;

	//服务实际返回给我们的数量
	uint32_t RespSize = 0;

	//服务返回给我们的id的起始值,这个0是我自己写的默认值,你也可以自己写啦
	uint64_t sysNo = 0;

	//这句话调用了idmaker服务.并返回一个我们需要的sysNo
	uint32_t idmakerResult = m_sysNoMaker.GetNeedIdsForU64(rCntlInfo, eBizType, ReqSize, RespSize, sysNo);

	if (idmakerResult != 0 || sysNo == 0)
	{
		C2C_WW_LOG_ERR(ERR_ERP_YUN_MAKEID_FAILED, "%s Get id failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u, Result:%u, SysNo:%ld",
				__FUNCTION__, rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, idmakerResult, sysNo);
		return ERR_ERP_YUN_MAKEID_FAILED;
	}

	ddwSysNo = sysNo;
}


uint32_t CAccountDao::CheckCommParam(
		const CCntlInfo& rCntlInfo,
		const std::string& strMachineKey,
		const std::string& strSource,
		const uint32_t dwSceneId)
{
	int32_t iRetCode = 0;

	//IPToString(rCntlInfo.getOperatorClientIP(),m_strClientIP);

	if(strMachineKey.empty())
	{
		iRetCode=ERR_ERP_COMMON_MACHINEKEY_INVALID;
	    C2C_WW_LOG_ERR(iRetCode,"MachineKey Error! MachineKey:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		strMachineKey.c_str(),rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);
		return iRetCode;
	}

	if(strSource.empty())
	{
		iRetCode=ERR_ERP_COMMON_SOURCE_INVALID;
	    C2C_WW_LOG_ERR(iRetCode,"Source Error! Source:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		strSource.c_str(),rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);
		return iRetCode;
	}

	if(dwSceneId==0)
	{
		iRetCode=ERR_ERP_COMMON_SCENEID_INVALID;
	    C2C_WW_LOG_ERR(iRetCode,"SceneId Error! SceneId:%u OpUin:%u MachineKey:%s Source:%s SceneId:%u",
	    		dwSceneId,rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);
		return iRetCode;
	}

	return iRetCode;
}
